package com.alticor.amwaychina.qqsharelib;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.tencent.connect.share.QQShare;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

import java.io.File;

/**
 * QQ share file
 */
public class QQShareUtil {
    public static final String APP_ID = "222222" ;
    public static void shareWebPage(Activity activity ,String title ,  String targetUrl,String summary,String appName){
        Tencent tencent = Tencent.createInstance(APP_ID, activity);
        final Bundle params = new Bundle();
        params.putString(QQShare.SHARE_TO_QQ_TITLE, title);
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL,targetUrl);
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary);
        params.putString(QQShare.SHARE_TO_QQ_APP_NAME, appName);
        tencent.shareToQQ(activity, params, new IUiListener() {
            @Override
            public void onCancel() {
                //Util.toastMessage(QQShareActivity.this, "onCancel: ");
            }
            @Override
            public void onComplete(Object response) {

            }
            @Override
            public void onError(UiError e) {

            }
        });
    }

    public static void shareLocalImage(Activity activity , String localFilPath){
        File file = new File(localFilPath) ;
        if(!file.exists()){
            Toast.makeText(activity,"文件不存在", Toast.LENGTH_SHORT).show();
            return ;
        }
        Tencent tencent = Tencent.createInstance(APP_ID, activity);
        final Bundle params = new Bundle();
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, localFilPath);
        tencent.shareToQQ(activity, params, new IUiListener() {
            @Override
            public void onCancel() {
                //Util.toastMessage(QQShareActivity.this, "onCancel: ");
            }
            @Override
            public void onComplete(Object response) {

            }
            @Override
            public void onError(UiError e) {

            }
        });
    }
}
